from sqlalchemy import Column, Integer, Date, Float, String, DateTime
from sqlalchemy.sql import func
from backend.config.database import Base


class WeatherData(Base):
    """气象数据表 - 17个指标"""
    __tablename__ = "weather_data"
    
    id = Column(Integer, primary_key=True, autoincrement=True, comment='主键')
    dt = Column(Date, unique=True, nullable=False, comment='日期')
    
    # 温度相关
    t_max = Column(Float, nullable=True, comment='最高气温')
    t_min = Column(Float, nullable=True, comment='最低气温')
    t_app_max = Column(Float, nullable=True, comment='最高体感温度')
    t_app_min = Column(Float, nullable=True, comment='最低体感温度')
    
    # 降水相关
    prec_sum = Column(Float, nullable=True, comment='降水量')
    rain_sum = Column(Float, nullable=True, comment='降雨量')
    show_sum = Column(Float, nullable=True, comment='阵雨量')
    snow_sum = Column(Float, nullable=True, comment='降雪量')
    prec_hrs = Column(Float, nullable=True, comment='降水小时数')
    
    # 天气状况
    wcode = Column(Integer, nullable=True, comment='天气代码')
    
    # 光照相关
    sun_dur = Column(Float, nullable=True, comment='日照时长')
    uv_max = Column(Float, nullable=True, comment='最大紫外线指数')
    
    # 风相关
    ws_max = Column(Float, nullable=True, comment='最大风速')
    wg_max = Column(Float, nullable=True, comment='最大阵风')
    wd_dom = Column(Integer, nullable=True, comment='主导风向')
    
    # 其他
    sw_rad = Column(Float, nullable=True, comment='短波辐射')
    et0 = Column(Float, nullable=True, comment='蒸散发')
    snowd_max = Column(Float, nullable=True, comment='最大积雪深度')
    
    created_at = Column(DateTime, default=func.now(), comment='入库时间')
    
    class Config:
        from_attributes = True